package net.sxnic.workflow.wfentity;

import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Lob;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import net.sxinfo.core.entity.AbstractEntity;
import net.sxnic.comm.attachment.Attachment;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Cascade;


@Entity
@Table(name = "wf_entity")
@BatchSize(size = 10)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class WfEntity extends AbstractEntity{

	private static final long serialVersionUID = -6661373020117837545L;
	
	/**
	 * 标题
	 */
	private String title;

	/**
	 * 主题词
	 */
	private String keyword;
	
	/**
	 * 文号
	 */
	private String wenhao;

	/**
	 * 类型1。receivedoc收文senddoc发文qingshi请示报告
	 */
	private String cate1;
	
	/**
	 * 类型2,一般不用，如果有小类别的话，再用此字段
	 */
	private String cate2;

	/**
	 * 收文登记人，发文拟稿人,流程的启动者
	 */
	private String initiator;
	
	/**
	 * 此文件，所属处室编码
	 */
	private String deptCode;
	
	/**
	 * 份数
	 */
	private String amount;

	/**
	 * 秘级
	 */
	private String secret;

	/**
	 * 紧急程度
	 */
	private String urgent;
	
	/**
	 * 张数
	 */
	private String pages;
	
	/**
	 * 日期 年
	 */
	private String cyear;

	/**
	 * 日期 月
	 */
	private String cmonth;

	/**
	 * 日期 日
	 */
	private String cday;
	
	/**
	 * 办理时限，一个日期。
	 */
	private String dealDate;
	
	/**
	 * 内容
	 */
	@Lob
	@Column(name="content_")
	private String content;
	
	/**
	 * 正文类型
	 */
	private String zwtype;
	
	/**
	 * 传阅字符串 
	 */
	private String chuanyue;
	
	/**
	 * 会签字符串
	 */
	private String huiqian;
	
	/**
	 * 会签类型
	 */
	private String huiqianCate;
	
	/**
	 * 拟稿年，主要是解决发文跨年问题
	 */
	private String nigaoYear;
	
	/**
	 * 附件列表（页面输入，在正文显示）
	 */
	@Lob
	private String attachmentName;
	
	@Column(name="int_1")
	private int int1;
	@Column(name="int_2")
	private int int2;
	@Column(name="int_3")
	private int int3;
	@Column(name="int_4")
	private int int4;
	@Column(name="int_5")
	private int int5;
	
	private String str1;
	private String str2;
	private String str3;
	private String str4;
	private String str5;
	
	private String str6;
	private String str7;
	private String str8;
	private String str9;
	private String st10;
	
	private String str11;
	private String str12;
	private String str13;
	private String str14;
	private String str15;
	
	private String str16;
	private String str17;
	private String str18;
	private String str19;
	private String str20;
	
	@Lob
	private String lob1;
	@Lob
	private String lob2;
	@Lob
	private String lob3;
	
	private String processId;
	
	/**
	 * 经办人，userName1,userName2
	 */
	@Lob
	private String assignees;
	
	/**
	 * 附件
	 */
	@OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
	@Cascade(value = { org.hibernate.annotations.CascadeType.ALL })
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	private Set<Attachment> attachments;

	public WfEntity() {
		super();
		attachments = new LinkedHashSet<Attachment>();
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getKeyword() {
		return keyword;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}

	public String getCate1() {
		return cate1;
	}

	public void setCate1(String cate1) {
		this.cate1 = cate1;
	}

	public String getCate2() {
		return cate2;
	}

	public void setCate2(String cate2) {
		this.cate2 = cate2;
	}

	public String getInitiator() {
		return initiator;
	}

	public void setInitiator(String initiator) {
		this.initiator = initiator;
	}

	public String getDeptCode() {
		return deptCode;
	}

	public void setDeptCode(String deptCode) {
		this.deptCode = deptCode;
	}

	public String getAmount() {
		return amount;
	}

	public void setAmount(String amount) {
		this.amount = amount;
	}

	public String getSecret() {
		return secret;
	}

	public void setSecret(String secret) {
		this.secret = secret;
	}

	public String getUrgent() {
		return urgent;
	}

	public void setUrgent(String urgent) {
		this.urgent = urgent;
	}

	public String getPages() {
		return pages;
	}

	public void setPages(String pages) {
		this.pages = pages;
	}

	public String getCyear() {
		return cyear;
	}

	public void setCyear(String cyear) {
		this.cyear = cyear;
	}

	public String getCmonth() {
		return cmonth;
	}

	public void setCmonth(String cmonth) {
		this.cmonth = cmonth;
	}

	public String getCday() {
		return cday;
	}

	public void setCday(String cday) {
		this.cday = cday;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getStr1() {
		return str1;
	}

	public void setStr1(String str1) {
		this.str1 = str1;
	}

	public String getStr2() {
		return str2;
	}

	public void setStr2(String str2) {
		this.str2 = str2;
	}

	public String getStr3() {
		return str3;
	}

	public void setStr3(String str3) {
		this.str3 = str3;
	}

	public String getStr4() {
		return str4;
	}

	public void setStr4(String str4) {
		this.str4 = str4;
	}

	public String getStr5() {
		return str5;
	}

	public void setStr5(String str5) {
		this.str5 = str5;
	}

	public String getStr6() {
		return str6;
	}

	public void setStr6(String str6) {
		this.str6 = str6;
	}

	public String getStr7() {
		return str7;
	}

	public void setStr7(String str7) {
		this.str7 = str7;
	}

	public String getStr8() {
		return str8;
	}

	public void setStr8(String str8) {
		this.str8 = str8;
	}

	public String getStr9() {
		return str9;
	}

	public void setStr9(String str9) {
		this.str9 = str9;
	}

	public String getSt10() {
		return st10;
	}

	public void setSt10(String st10) {
		this.st10 = st10;
	}

	public String getLob1() {
		return lob1;
	}

	public void setLob1(String lob1) {
		this.lob1 = lob1;
	}

	public String getLob2() {
		return lob2;
	}

	public void setLob2(String lob2) {
		this.lob2 = lob2;
	}

	public String getLob3() {
		return lob3;
	}

	public void setLob3(String lob3) {
		this.lob3 = lob3;
	}

	public Set<Attachment> getAttachments() {
		return attachments;
	}

	public void setAttachments(Set<Attachment> attachments) {
		this.attachments = attachments;
	}

	public String getProcessId() {
		return processId;
	}

	public void setProcessId(String processId) {
		this.processId = processId;
	}

	public String getZwtype() {
		return zwtype;
	}

	public void setZwtype(String zwtype) {
		this.zwtype = zwtype;
	}

	public String getAttachmentName() {
		return attachmentName;
	}

	public void setAttachmentName(String attachmentName) {
		this.attachmentName = attachmentName;
	}

	public int getInt1() {
		return int1;
	}

	public void setInt1(int int1) {
		this.int1 = int1;
	}

	public int getInt2() {
		return int2;
	}

	public void setInt2(int int2) {
		this.int2 = int2;
	}

	public int getInt3() {
		return int3;
	}

	public void setInt3(int int3) {
		this.int3 = int3;
	}

	public int getInt4() {
		return int4;
	}

	public void setInt4(int int4) {
		this.int4 = int4;
	}

	public int getInt5() {
		return int5;
	}

	public void setInt5(int int5) {
		this.int5 = int5;
	}

	public String getWenhao() {
		return wenhao;
	}

	public void setWenhao(String wenhao) {
		this.wenhao = wenhao;
	}

	public String getChuanyue() {
		return chuanyue;
	}

	public void setChuanyue(String chuanyue) {
		this.chuanyue = chuanyue;
	}

	public String getHuiqian() {
		return huiqian;
	}

	public void setHuiqian(String huiqian) {
		this.huiqian = huiqian;
	}

	public String getHuiqianCate() {
		return huiqianCate;
	}

	public void setHuiqianCate(String huiqianCate) {
		this.huiqianCate = huiqianCate;
	}

	public String getStr11() {
		return str11;
	}

	public void setStr11(String str11) {
		this.str11 = str11;
	}

	public String getStr12() {
		return str12;
	}

	public void setStr12(String str12) {
		this.str12 = str12;
	}

	public String getStr13() {
		return str13;
	}

	public void setStr13(String str13) {
		this.str13 = str13;
	}

	public String getStr14() {
		return str14;
	}

	public void setStr14(String str14) {
		this.str14 = str14;
	}

	public String getStr16() {
		return str16;
	}

	public void setStr16(String str16) {
		this.str16 = str16;
	}

	public String getStr17() {
		return str17;
	}

	public void setStr17(String str17) {
		this.str17 = str17;
	}

	public String getStr18() {
		return str18;
	}

	public void setStr18(String str18) {
		this.str18 = str18;
	}

	public String getStr19() {
		return str19;
	}

	public void setStr19(String str19) {
		this.str19 = str19;
	}

	public String getNigaoYear() {
		return nigaoYear;
	}

	public void setNigaoYear(String nigaoYear) {
		this.nigaoYear = nigaoYear;
	}

	public String getStr15() {
		return str15;
	}

	public void setStr15(String str15) {
		this.str15 = str15;
	}

	public String getStr20() {
		return str20;
	}

	public void setStr20(String str20) {
		this.str20 = str20;
	}

	public String getDealDate() {
		return dealDate;
	}

	public void setDealDate(String dealDate) {
		this.dealDate = dealDate;
	}

	public String getAssignees() {
		return assignees;
	}

	public void setAssignees(String assignees) {
		this.assignees = assignees;
	}
	
	/**
	 * 添加经办人
	 * @param assignee
	 */
	public void addAssignee(String assignee){
		if(StringUtils.isBlank(this.assignees)){
			assignees = assignee;
		}
		
		if(!StringUtils.contains(this.assignees, assignee)){
			this.assignees = this.assignees+","+assignee;
		}
	}
	
	/**
	 * 移除经办人
	 * @param assignee
	 */
	public void removeAssignee(String assignee){
		if(StringUtils.isBlank(this.assignees)){
			return;
		}else{
			if(StringUtils.contains(this.assignees, ","+assignee)){
				this.assignees = StringUtils.remove(this.assignees, ","+assignee);
				return;
			}
			
			if(StringUtils.contains(this.assignees, assignee)){
				this.assignees = StringUtils.remove(this.assignees, assignee);
			}
		}
	}
}
